﻿using JESAI.Redis.Enums;
using System;
using System.Collections.Generic;
using System.Text;

namespace JESAI.Redis.Internal.Models
{
    internal class RedisClientConnectionState
    {
        public string Host { get; set; }

        public int Port { get; set; }

        public int FailCount { get; set; }

        public ConnectStateEnum ConnectState { get; set; }

        public string ErrorMessage { get; set; }

        public RedisClientConnectionState(string host, int port)
        {
            this.Host = host;
            this.Port = port;
            this.ConnectState = ConnectStateEnum.Valid;
            this.FailCount = 0;
        }

        /// <summary>
        /// 设置有效
        /// </summary>
        public void SetValid()
        {
            this.FailCount = 0;
            this.ConnectState = ConnectStateEnum.Valid;
            this.ErrorMessage = string.Empty;
        }

        public void SetInValid(string errorMessage)
        {
            this.FailCount++;
            this.ConnectState = ConnectStateEnum.InValid;
            this.ErrorMessage = errorMessage;
        }
    }
}
